<?php
/**
 * *********************************************************************************************************************
 * 寄件登记
 * *********************************************************************************************************************
 */
namespace soa\enrollment;
use soa\client;

class enrollment extends client
{
    /**
     * @var string
     */
    protected $service_url = 'http://finance.core.kuaidihelp.com/';
    /**
     * @var string
     */
    protected $service_name = 'kuaidihelp_finance';

    /**
     * 寄件信息登记
     * @param array $data
     * @return bool
     */
    public function add(array $data)
    {
        if(empty($data) || !is_array($data)) {
            return false;
        }
        $result = $this->post('v1/enrollment/add', array('data' => $data));
        if($result ==1)
            return true;
        else
            return false;
    }

    /**
     * 寄件信息查询
     * @param $waybill_no
     * @return array
     */
    public function get($waybill_no)
    {

    }

    public function getById($id)
    {
        $result = $this->post('v1/enrollment/getById', ['id' => $id]);
        if(!empty($result) && is_array($result)){
            return $result;
        }
        return [];
    }

    public function getByWayBill($waybill_no,$courierId)
    {
        $result = $this->post('v1/enrollment/getByWayBill', ['waybill_no' => $waybill_no,'courierId'=>$courierId]);
        if(!empty($result) && is_array($result)){
            return $result;
        }
        return [];
    }

    /**
     * 获取快递寄件列表
     * @param $courier_id
     * @param int $page
     * @param int $page_size
     * @param $version
     * @return array
     */
    public function getList($courier_id, $page = 1, $page_size = 10,$version)
    {
        $result = $this->post(
            'v1/enrollment/getList',
            array('courier_id' => $courier_id, 'page' => $page, 'page_size' => $page_size,'version'=>$version)
        );
        if(!empty($result) && is_array($result)){
            return $result;
        }
        return [];
    }

    public function enrollmentAddOffline($courier_id,$pay_money,$order_id,$source=''){
        $result = $this->post('v1/enrollment/addOffline', ['courier_id' => $courier_id,'money' =>$pay_money,'order_id'=>$order_id ,'source'=>$source]);
        if(!empty($result)){
            return $result;
        }
        return [];
    }

    public function enrollmentaddOfflineWaybill($insert_id,$waybill_list){
        $result = $this->post('v1/enrollment/addOfflineWaybill', ['insert_id' => $insert_id,'waybill_list' =>$waybill_list]);
        if(!empty($result)){
            return $result;
        }
        return [];
    }
}